package usf.gwt.ui.demo.tools;

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.HasHTML;
import com.google.gwt.user.client.ui.Widget;

public class Code extends Widget implements HasHTML {
	
	protected CodeFormatter formatter;
	
	public Code() {
		Element e = Document.get().createPreElement();
		e.addClassName("brush:xml;");
		setElement(e);
		setFormatter(CodeFormatter.XML_FORMATER);
	}
	
	public void setFormatter(CodeFormatter formatter) {
		this.formatter = formatter;
	}
	
	@Override
	public String getHTML() {
		return getElement().getInnerText();
	}
	@Override
	public void setHTML(String html) {
		getElement().setInnerText(formatter.format(html));
	}

	@Override
	public String getText() {
		return getElement().getInnerText();
	}
	@Override
	public void setText(String text) {
		getElement().setInnerText(text);
	}

}
